package com;

public class DistBetwNodes {
	
	/*This method finds the great circle distance, in radians, between 2 points by using
	the Haversine Formula.*/
	
	public static double get_distance(Node node, Node prev_node) {
		double lat1 = Math.toRadians(Double.parseDouble(node.lat));
		double lat2 = Math.toRadians(Double.parseDouble(prev_node.lat));
		double lon1 = Math.toRadians(Double.parseDouble(node.lon));
		double lon2 = Math.toRadians(Double.parseDouble(prev_node.lon));

		double dist;
		
		double dlat = Math.abs(lat1 - lat2);
		double dlon = Math.abs(lon1 - lon2);
		
		double a = Math.pow(Math.sin(dlat/2),2.0) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2),2.0);
		
		dist = 2 * Math.asin(Math.sqrt(a));
		
		return dist;
	}
	

}
